// part1:C11:ex11.20.cpp
// total of words. usage of insert.
#include <cstddef>
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[]) {
  ifstream in(argv[1]);
  if (!in) {
    cout << "failed open input file!" << endl;
    exit(1);
  }

  map<string, size_t> word_count;
  string word;
  while (in >> word) {
    auto ret = word_count.insert({word, 1});
    if (!ret.second) {
      ++ret.first->second;
    }
  }

  for  (const auto &w : word_count) {
    cout << w.first << " is : " << w.second << endl;
  }

  return 0;
}
